<?php

	/**
	* Department - Node view
	* @author trungdt
	* @since Sep 4, 2011
	* 
	*/

	if (!defined('EXPONENT')) exit('');

	global $db;

	// input : seo-name
	$id = ""; $node= null;
	if (isset($_REQUEST['id']))
	{
		$id=_ab_safe_html_string($_REQUEST['id']);
		if (is_int($id))
		{
			// get node by ID
			$id=intval($id);
			$node=$db->selectObject("depmodule_dep","id = {$id}");
		}
		else
		{
			// get node by seo-name
			$node=$db->selectObject("depmodule_dep","seo_name = '{$id}'");
		}
	}
	// check again
	if (!$node)
	{
		echo SITE_404_HTML;
	}
	else
	{
		// get config
		$config = $db->selectObject('depmodule_config',"location_data='{$node->location_data}'");
		// get tree nodes list
		$tree=depmodule::getTreeLinks($node->location_data, $node->seo_name);
		$mysec=depmodule::getSectionContainDep($node->location_data);
		$dep_link="";
		if ($mysec)
		{
			$params=array();
			$params['section']=$mysec->section;
			$dep_link=exponent_core_makeLink($params);
		}
		
		// Nov 1, 2011 - trungdt
		// add breadcum backlink
		$breadcum=array();
		$breadcum_current=clone $node;
		do{
			$breadcum[]=clone $breadcum_current;
			if ($breadcum_current->parent_id != 0)
				$breadcum_current=$db->selectObject("depmodule_dep", "id = ".$breadcum_current->parent_id);
			if ($breadcum_current->parent_id == 0 && $breadcum_current->id != $node->id)
				$breadcum[]=$breadcum_current; // add if last item is the root
		}while ($breadcum_current->parent_id > 0);
		$breadcum=array_reverse($breadcum);
		
		_ab_theme_action_register_title($node->title . " - ".SITE_TITLE,0,1);
		_ab_theme_action_register_title($node->search_des,0,0);
		
		$template = new template('depmodule',"Default",$loc);
		$template->assign('config',$config);
		$template->assign('dep_link',$dep_link);
		$template->assign('links',$tree);
		$template->assign('main_content',$node->content);
		$template->assign('breadcum',$breadcum);
		$template->assign('breadcum_count',count($breadcum));
		
		$node->article_src=$node->seo_name.$node->id;
		$template->assign('current_node',$node);
		
		$template->register_permissions(array('administrate','configure','create','edit','delete'),$loc);
		
		exponent_flow_set(SYS_FLOW_PUBLIC);
		$template->output();
	}
	//
?>